public with sharing class MyList implements Iterable<Student> {
    
    public List<Student> data {set; get;}
    public Integer idx = 0;

    public MyList(){}

    public MyList(List<Student> data) {
        this.data = data;
    }

    public Iterator<Student> iterator() {
        return new MyIterator(this);
    }

    private class MyIterator implements Iterator<Student> {

        private MyList outerRef;
        public MyIterator(MyList outerRef) {
            this.outerRef = outerRef;
        }

        public Boolean hasNext(){
            return outerRef.idx < outerRef.data.size();
        }
        public Student next(){
            Student stu = outerRef.data.get(outerRef.idx);
            outerRef.idx++;
            return stu;
        }
    }

}